export default {
  defaultLoadingOptions: {
    lock: true,
    text: "请稍后...",
    spinner: "el-icon-loading",
    background: "rgba(0, 0, 0, 0.5)"
  },
  defaultTitleEnd: " - 正福易找标，你贴身的数据专家",
  IEVersion() {
    // 取得浏览器的userAgent字符串
    let userAgent = navigator.userAgent;
    // 判断是否为小于IE11的浏览器
    let isLessIE11 =
      userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1;
    // 判断是否为IE的Edge浏览器
    let isEdge = userAgent.indexOf("Edge") > -1 && !isLessIE11;
    // 判断是否为IE11浏览器
    let isIE11 =
      userAgent.indexOf("Trident") > -1 && userAgent.indexOf("rv:11.0") > -1;
    if (isLessIE11) {
      var IEReg = new RegExp("MSIE (\\d+\\.\\d+);");
      // 正则表达式匹配浏览器的userAgent字符串中MSIE后的数字部分，，这一步不可省略！！！
      IEReg.test(userAgent);
      // 取正则表达式中第一个小括号里匹配到的值
      var IEVersionNum = parseFloat(RegExp["$1"]);
      if (IEVersionNum === 7) {
        // IE7
        return "7";
      } else if (IEVersionNum === 8) {
        // IE8
        return "8";
      } else if (IEVersionNum === 9) {
        // IE9
        return "9";
      } else if (IEVersionNum === 10) {
        // IE10
        return "10";
      } else {
        // IE版本<7
        return "6";
      }
    } else if (isEdge) {
      // edge
      return "edge";
    } else if (isIE11) {
      // IE11
      return "11";
    } else {
      // 不是ie浏览器
      return "0";
    }
  },
  getScrollTop() {
    //获取scrollTop的值，兼容所有浏览器
    let scrollTop =
      document.documentElement.scrollTop ||
      window.pageYOffset ||
      document.body.scrollTop;
    return scrollTop;
  },
  setScrollTop(scroll_top) {
    //设置scrollTop的值，兼容所有浏览器
    document.documentElement.scrollTop = scroll_top;
    window.pageYOffset = scroll_top;
    document.body.scrollTop = scroll_top;
  },
  getTimestamp(num = 13, date) {
    //获取时间戳
    let _date = date ? new Date(date) : new Date();
    return num == 13 ? _date.getTime() : Math.round(_date.getTime() / 1000);
  },
  formatDate(time, type = "-") {
    function isZero(m) {
      return m < 10 ? "0" + m : m;
    }

    var y = time.getFullYear();

    var m = time.getMonth() + 1;

    var d = time.getDate();

    var h = time.getHours();

    var mm = time.getMinutes();

    var s = time.getSeconds();

    console.log(
      y +
        type +
        isZero(m) +
        type +
        isZero(d) +
        " " +
        isZero(h) +
        ":" +
        isZero(mm) +
        ":" +
        isZero(s)
    );
    return (
      y +
      type +
      isZero(m) +
      type +
      isZero(d) +
      " " +
      isZero(h) +
      ":" +
      isZero(mm) +
      ":" +
      isZero(s)
    );
  },
  formatSecond(s) {
    //格式化秒
    return `${Math.floor(s / 60 / 60 / 24)}天${Math.floor(s / 60 / 60) %
      24}时${Math.floor(s / 60) % 60}分${s % 60}秒`;
  },
  testPhoneNumber(value) {
    //验证手机号码
    return /^1[34578]\d{9}$/.test(value);
  },
  testEmail(value) {
    let myReg = /^[-_A-Za-z0-9]+@([_A-Za-z0-9]+.)+[A-Za-z0-9]{2,3}$/;
    return myReg.test(value);
  },
  checkIdCard(str) {
    //15位数身份证正则表达式
    let arg1 = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/;
    //18位数身份证正则表达式
    let arg2 = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[A-Z])$/;
    if (str.match(arg1) == null && str.match(arg2) == null) {
      return false;
    } else {
      return true;
    }
  },
  isArray(o) {
    //判断是否为数组
    return Object.prototype.toString.call(o) == "[object Array]";
  },

  /**
   *  把html转义成HTML实体字符
   * @param str
   * @returns {string}
   * @constructor
   */
  htmlEncode(str) {
    var s = "";
    if (str.length === 0) {
      return "";
    }
    s = str.replace(/&/g, "&amp;");
    s = s.replace(/</g, "&lt;");
    s = s.replace(/>/g, "&gt;");
    s = s.replace(/ /g, "&nbsp;");
    // eslint-disable-next-line no-useless-escape
    s = s.replace(/\'/g, "&#39;"); //IE下不支持实体名称
    // eslint-disable-next-line no-useless-escape
    s = s.replace(/\"/g, "&quot;");
    return s;
  },

  /**
   *  转义字符还原成html字符
   * @param str
   * @returns {string}
   * @constructor
   */
  htmlRestore(str) {
    var s = "";
    if (str.length === 0) {
      return "";
    }
    s = str.replace(/&amp;/g, "&");
    s = s.replace(/&lt;/g, "<");
    s = s.replace(/&gt;/g, ">");
    s = s.replace(/&nbsp;/g, " ");
    s = s.replace(/&#39;/g, "'");
    s = s.replace(/&quot;/g, '"');
    return s;
  },
  // 加密文字方法
  addStyle() {
    const base64 =
      "AAEAAAALAIAAAwAwR1NVQiCLJXoAAAE4AAAAVE9TLzLBvcXsAAABjAAAAGBjbWFwBAZangAAAhgAAAIGZ2x5ZnsY9ekAAAQ4AAADUGhlYWQkKTYpAAAA4AAAADZoaGVhEvkIdAAAALwAAAAkaG10eDb+AAAAAAHsAAAALGxvY2EDzgSUAAAEIAAAABhtYXhwARgAMgAAARgAAAAgbmFtZcrWmLMAAAeIAAACNHBvc3Q25ze/AAAJvAAAAMcAAQAACHf96AAACoAAAAAACoAAAQAAAAAAAAAAAAAAAAAAAAsAAQAAAAEAALHri3pfDzz1AAsIAAAAAADdRPW5AAAAAN1E9bkAAP/nCoAF0wAAAAgAAgAAAAAAAAABAAAACwAmAAMAAAAAAAIAAAAKAAoAAAD/AAAAAAAAAAEAAAAKADAAPgACREZMVAAObGF0bgAaAAQAAAAAAAAAAQAAAAQAAAAAAAAAAQAAAAFsaWdhAAgAAAABAAAAAQAEAAQAAAABAAgAAQAGAAAAAQAAAAQFAAGQAAUAAAaqB2QAAAF6BqoHZAAABREAhAK5AAACAAUDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFBmRWQAwFU1VZIId/3oAPMJagIYAAAAAQAAAAAAAAAAAAAAAAACCoAAAARzAAAEcwAABHMAAARzAAAEcwAABHMAAARzAAAEcwAABHMAAARzAAAAAAAFAAAAAwAAACwAAAAEAAABfgABAAAAAAB4AAMAAQAAACwAAwAKAAABfgAEAEwAAAAKAAgAAgACVTVVOVVcVZL//wAAVTVVOVVcVYz//wAA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ovL2ZvbnRlbGxvLmNvbQBNAGkAYwByAG8AcwBvAGYAdAAgAFkAYQBIAGUAaQBSAGUAZwB1AGwAYQByAHMAdgBnAHQAbwBmAG8AbgB0AHMAdgBnAHQAbwBmAG8AbgB0AFYAZQByAHMAaQBvAG4AIAAxAC4AMABzAHYAZwB0AG8AZgBvAG4AdABHAGUAbgBlAHIAYQB0AGUAZAAgAGIAeQAgAHMAdgBnADIAdAB0AGYAIABmAHIAbwBtACAARgBvAG4AdABlAGwAbABvACAAcAByAG8AagBlAGMAdAAuAGgAdAB0AHAAOgAvAC8AZgBvAG4AdABlAGwAbABvAC4AYwBvAG0AAgAAAAAAAAAbAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALAQIBAwEEAQUBBgEHAQgBCQEKAQsBDAANMTYyOTQzOTI4OTQ3Mw0xNjI5NDM5Mjg5NDczDTE2Mjk0MzkyODk0NzMNMTYyOTQzOTI4OTQ3Mw0xNjI5NDM5Mjg5NDczDTE2Mjk0MzkyODk0NzMNMTYyOTQzOTI4OTQ3Mw0xNjI5NDM5Mjg5NDczDTE2Mjk0MzkyODk0NzMNMTYyOTQzOTI4OTQ3MwAAAA==";
    let oStyle = document.createElement("style");
    oStyle.innerText = `@font-face {
                                font-family: "Microsoft YaHei";
                                src: url(data:application/x-font-woff;charset=utf-8;base64,${base64});
                              }`;
    document.head.appendChild(oStyle);
  }
}
